package com.bsdsma.visonManagementSystemapp.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bsdsma.visonManagementSystemapp.dto.BaogaoWithUserDto;
import com.bsdsma.visonManagementSystemapp.entity.Baogao;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import com.bsdsma.visonManagementSystemapp.dto.DataGroupByDateDto;

import java.util.Date;
import java.util.List;

/**
* 视力报告 Mybatis数据库操作接口
*/
@Mapper
public interface BaogaoMapper extends BaseMapper<Baogao> {

    @Select("SELECT b.*, u.name, u.xuexiao, u.nianji, u.banji, u.cellphone_number as cellphoneNumber, u.account " +
            "FROM baogao b " +
            "LEFT JOIN user u ON b.xuehao = u.xuehao AND b.status = u.status " +
            "WHERE u.status = 0 " +
            "AND ${ew.sqlSegment}")
    IPage<BaogaoWithUserDto> selectPageWithUser(Page<BaogaoWithUserDto> page, @Param("ew") Object wrapper);

    @Select("select DATE_FORMAT(ct, '%Y-%m-%d') `day`, count(1) num from baogao where ct >= #{beginDate} and ct <= #{endDate} group by `day` order by `day`;")
    List<DataGroupByDateDto> countByDay(@Param(value = "beginDate") Date beginDate, @Param(value = "endDate") Date endDate);
}
